<script setup lang="ts">
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
import { getBalance, getHasPayPassword, getPayPasswordFree } from '@/utils/tools'
import { autoUpdate, getFont, getUserInfo, getPhoneInfo, getAuthorize } from '@/utils/miniInit'
import { useOrderStore, useMemberStore, usePagesMachineIdStore } from './stores'
import { getCityName } from '@/utils/tools'
import { provide } from 'vue'
import useQuery from '@/hooks/useQuery'

onLaunch(() => {
  getPhoneInfo()
  getFont()
})

onShow(() => {
  autoUpdate()
  /** 登录判断 */
  const loginPromise = new Promise((resolve, reject) => {
    getCityName()
      .then(() => {
        console.log('getCityName success')
        getUserInfo().then((res) => {
          console.log('getUserInfo：：：：：：', res)
          resolve(res)
        })
      })
      .catch((err) => {
        console.log('getCityName error')
        reject(err)
      })
  })
  console.log('App Show::::::', loginPromise)
  /** 全局参数 */
  const globalData = { loginPromise }
  provide('globalData', globalData)
  const memberStore = useMemberStore()
  if (memberStore?.token) {
    Promise.all([getBalance(), getHasPayPassword(), getPayPasswordFree()])
  }
  const orderStore = useOrderStore()
  orderStore.setOrderStatus('') // 页面初始化 清空订单状态 防止本地缓存的订单状态异常
})

onHide(() => {
  console.log('App Hide')
  usePagesMachineIdStore().clearPagesMachineId() // 切换前后台的时候清除分享进入的设备id
  useQuery().deleteQueryParams() // 切换前后台清除参数
})
</script>

<style lang="scss">
// 字体图标
@import '@/static/iconfont.css';
@import '@/styles/fonts.scss';
@import '@/styles/common.css';
/**彩色icon */
@import '@/styles/iconfont-weapp-icon.css';

:root {
  --primary-color: $uni-color-motif; /* 设置主题颜色变量 */
}

view,
navigator,
input,
scroll-view {
  box-sizing: border-box;
}

button::after {
  border: none;
}

swiper,
scroll-view {
  flex: 1;
  height: 100%;
  overflow: hidden;
}

image {
  width: 100%;
  height: 100%;
  vertical-align: middle;
}

// 两行省略
.ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
</style>
